package com.wwh.furns.web;

import com.wwh.furns.entity.Admin;
import com.wwh.furns.entity.Member;
import com.wwh.furns.service.AdminService;
import com.wwh.furns.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Albert
 * @date 2024/5/30-19:16
 * @describe
 */
public class AdminServlet extends BasicServlet{
    AdminService adminService = new AdminServiceImpl();

    /**
     * 处理管理员登陆请求
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收用户登录信息
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        req.setAttribute("username", username);

        //判断用户名是否可登录
        if (adminService.loginAdmin(new Admin(null, username, password))) {
            //登录
            //System.out.println("登录成功");
            req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req, resp);
        } else {
            //System.out.println("登录失败");
            req.setAttribute("errorMsg", "用户名或密码错误~");
            req.getRequestDispatcher("/views/manage/manage_login.jsp").forward(req, resp);

        }
    }
}
